package mscs.client.member.view;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import mscs.data.pojo.Member;

public class TableModelFactory {
	public static Vector<String> columnNames = new Vector<String>();
 	public static DefaultTableModel getNullMemberModel(){
		setColumnNames();
		return new DefaultTableModel(null, columnNames);
        }
	
	public static Vector getColumnNames(){
		setColumnNames();
		return columnNames;
	}
	private static void setColumnNames(){
		if(columnNames.isEmpty()){
			columnNames.add("编号");
			columnNames.add("姓名");
			columnNames.add("生日");
			columnNames.add("性别");
			columnNames.add("联系方式");
			columnNames.add("积分总额");
			columnNames.add("积分余额");
		}
	}
	
	//返回newList中所有List的一个新的二维数组
	public static Vector<Vector<String>> MemberListDataVector(List<Member> newList) {
		Vector<Vector<String>> newVector = new Vector<Vector<String>>();
		for(Member member: newList){
			newVector.add((Vector<String>)toStringArray(member));
		}
		return newVector;
	}
	//将每一条记录的每一个字段转换为一个字符串，并组合成一个List返回
	private static List<String> toStringArray(Member member){		
		Vector<String> list = new Vector<String>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		list.add(member.getId());
		list.add(member.getName());
		list.add(sdf.format(member.getBirthday()));
		list.add(member.genderToString());
		list.add(member.getContact());
		list.add(((Integer)member.getTotalPoints()).toString());
		list.add(((Integer)member.getLeftPoints()).toString());
		return list;
	}
	
}
